import { clearConversationUnread } from '../../util/rongCloud/cloudUtil';

const chat = {
  namespaced: true,

  state: {
    sEmojiActive: false,
    // 放房源卡片信息
    sHouseItem: {},
    canSendHouseCard: false,
    // 当前聊天对象的所有消息,
    // 设值后说明你已经进来看当前聊天对象的所有聊天信息了
    sChatHistoryList: [],
    // 所有会话列表
    sConversationList: [],
    // deprecated: 融云环境初始化好了吗
    cloudGoodToGo: false,
  },
  mutations: {
    set_sEmojiActive: (state, val) => {
      state.sEmojiActive = val;
    },
    set_sHouseItem: (state, val) => {
      state.sHouseItem = val;
    },
    set_canSendHouseCard: (state, val) => {
      state.canSendHouseCard = val;
    },
    set_sChatHistoryList: (state, val) => {
      state.sChatHistoryList = val;
      clearConversationUnread(state.sChatHistoryList[0].targetId);
    },
    set_sConversationList: (state, val) => {
      state.sConversationList = val;
    },
    set_cloudGoodToGo: (state, val) => {
      state.cloudGoodToGo = val;
    },
  },
  getters: {
    sEmojiActive: (state) => state.sEmojiActive, // 是否显示emoji popup
    sHouseItem: (state) => state.sHouseItem,
    canSendHouseCard: (state) => state.canSendHouseCard,
    sChatHistoryList: (state) => state.sChatHistoryList,
    cloudGoodToGo: (state) => state.cloudGoodToGo,
    sConversationList: (state) => state.sConversationList,
  },
  actions: {
    set_sEmojiActive: ({ commit }, val) => {
      return commit('set_sEmojiActive', val);
    },
    set_sHouseItem: ({ commit }, val) => {
      return commit('set_sHouseItem', val);
    },
    set_canSendHouseCard: ({ commit }, val) => {
      return commit('set_canSendHouseCard', val);
    },
    set_sChatHistoryList: ({ commit }, val) => {
      return commit('set_sChatHistoryList', val);
    },
    set_sConversationList: ({ commit }, val) => {
      return commit('set_sConversationList', val);
    },
    set_cloudGoodToGo: ({ commit }, val) => {
      return commit('set_cloudGoodToGo', val);
    },
  },
};

export default chat;
